package com.ruoyi.web.controller.grade;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.grade.domain.entity.StudentCourseGrade;
import com.ruoyi.grade.domain.entity.StudentCourseGradeother;
import com.ruoyi.grade.domain.entity.StudentTotalGrade;
import com.ruoyi.grade.service.IStudentGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学生成绩查询 控制器
 */
@CrossOrigin
@RestController
@RequestMapping("/system/grade")
@PreAuthorize("@ss.hasPermi('student:grade:controller')")
public class StudentGradeController extends BaseController {
    
    @Autowired
    private IStudentGradeService studentGradeService;
    
    /**
     * 根据学年和学期查询学生成绩
     */
    @GetMapping("/list")
    public R getGradesByAcademicYearAndSemester(
            @RequestParam(required = true) String studentId,
            @RequestParam(required = false) String academicYear,
            @RequestParam(required = false) String semester) {

        if(getUserId() != 1202l) studentId = getStudentId();
        
        List<StudentCourseGrade> courseGradeList = studentGradeService.selectStudentCourseGradeList(studentId, academicYear, semester);
        List<StudentTotalGrade> totalGradeList = studentGradeService.selectStudentTotalGradeList(studentId, academicYear, semester);
        List<StudentCourseGradeother> courseGradeListother = studentGradeService.selectStudentCourseGradeListother(studentId, academicYear, semester);
        
        Map<String, Object> result = new HashMap<>();
        result.put("studentCourseGradeList", courseGradeList);
        result.put("studentCourseGradeListother", courseGradeListother);
        result.put("studentTotalGradeList", totalGradeList);
        result.put("studentId", getStudentId());
        return R.ok(result);
    }
} 